#include "Thread.hpp"
#include <unistd.h>
#include <stdlib.h>
#include <iostream>

using std::cout;
using std::endl;

class MyThread
: public Thread
{
    void run() override
    {   //每一秒生产一个随机数，一共生产10个
        int cnt = 10;
        srand(time(NULL));
        while(cnt-- > 0) {
            int num = rand() % 100;
            cout << "sub thread " << pthread_self()  
                 << ": num = " << num << endl;
            sleep(1);
        }
    }
};

int main()
{
    Thread * pthread = new MyThread;
    pthread->start();
    pthread->join();

    //希望该语句编译不通过
    //pthread->run();//error
    
    delete pthread;

    cout << "\n直接创建线程的派生类对象，来执行子线程" << endl;
    //也可以直接创建派生类对象
    MyThread mythread;
    mythread.start();
    mythread.join();

    return 0;
}

